package edu.stu.cs.software.family.admin.web.spring.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import edu.stu.cs.software.family.admin.domain.User;
import edu.stu.cs.software.family.admin.service.UserManager;
import edu.stu.cs.software.family.base.web.spring.controller.GenericController;

/**
 * This @RestController returns the retrieved data as a string
 * 
 * @author Administrator
 *
 */
@RestController
@RequestMapping(value = "/user")
public class UserController extends GenericController<User, Long, UserManager> {

	UserManager userManager;

	@Autowired
	public void setUserManager(UserManager userManager) {
		this.userManager = userManager;
		this.manager = this.userManager;
	}
<<<<<<< HEAD
	@RequestMapping(value = "/login", method = RequestMethod.POST, produces = "application/json;charset=UTF-8", consumes = "application/json")
=======
	@RequestMapping(value = "/login", method = RequestMethod.POST)
>>>>>>> origin/master
	public String dologin(@RequestBody User user)
	{
		String userName = user.getUserName();
		String password = user.getPassword();
		user = this.userManager.findByName(userName);
		if (user == null) {
            return "error";
        }
        if (!password.equals(((User) user).getPassword())) {
            return "error";
        }
        return "success";
	}
	@RequestMapping(value = "/test", method = RequestMethod.POST)
	public String test(@RequestParam String text) {
		if(text!=null) {
		return "sucess";
		}else {
			return "error";
		}
	}
}
